﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using RPGProject.Data_Structures;
namespace Lexer.SyntaxTree
{
    /// <summary>
    /// A property node.  Contains information relevant towards retrieving properties from GameObjects.
    /// </summary>
    class PropertySyntaxNode : ArgumentSyntaxNode
    {
        private Vector<String> propertyValues;
        public PropertySyntaxNode()
        {
            this.propertyValues = new Vector<String>();
        }
        public String this[int i]
        {
            get { return this.propertyValues[i]; }
            set { this.propertyValues[i] = value; }
        }
        public int Size
        {
            get { return this.propertyValues.Count; }
        }
        /// <summary>
        /// Gets the rest of the string, from the starting point.
        /// </summary>
        /// <param name="start"></param>
        /// <returns></returns>
        public String RestOf(int start)
        {
            String ret = "";
            bool first = true;
            for (int i = start; i < this.Size; i++)
            {
                if (first)
                    first = false;
                else
                    ret += ".";
                ret += this[i];
            }
            return ret;
        }
        public String PropertyName
        {
            get 
            {
                String ret = "";
                bool first = true;
                foreach (String s in this.propertyValues)
                {
                    if (first)
                        first = false;
                    else
                        ret += ".";
                    ret += s;
                }
                return ret; 
            }
            set 
            {
                String[] props = value.Split(new char[] { '.' });
                this.propertyValues.Clear();
                for (int i = 0; i < props.Count(); i++)
                {
                    this.propertyValues.Add(props[i]);
                }
            }
        }

        public override string ToString()
        {
            return "Property: " + this.PropertyName;
        }
    }
}
